package com.cskaoyan.javase.io._1byte._2filein;

import javax.swing.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 使用FileInputStream的注意事项
 *      1.文件字节输入流要求文件必须是存在的，如果不存在就会报错抛出异常。
 *      2.将读取到的字节数据转换成字符串时,可以考虑
 *          String(byte bytes[], int offset, int length)
 *
 * @since 16:20
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Notice {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("a.txt");
        byte[] buf = new byte[4];
        int readCount = in.read(buf);
        // 4
        System.out.println(readCount);
        // abcd
        System.out.println("读取到的数据是:" + new String(buf, 0, readCount));

        int readCount2 = in.read(buf);
        // 2
        System.out.println(readCount2);
        // ef
        // String(byte bytes[], int offset, int length) {
        System.out.println("读取到的数据是:" + new String(buf, 0, readCount2));

        // close关闭流
        in.close();
    }
}
